//
//  setUpTableViewController.m
//  FoodCorner
//
//  Created by lanou3g on 16/3/1.
//  Copyright © 2016年 zhangchao. All rights reserved.
//

#import "setUpTableViewController.h"

#import "setUpTool.h"
#import "setUpModel.h"
#import "setUpTableViewCell.h"
#import "LoginTableViewController.h"
#import "FirstLandViewController.h"

#import "AppDelegate.h"

@interface setUpTableViewController ()

@end

@implementation setUpTableViewController

- (instancetype)initWithStyle:(UITableViewStyle)style{
    if (self = [super initWithStyle:UITableViewStyleGrouped]) {
        
    }
    return self;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.tableView registerClass:[setUpTableViewCell class] forCellReuseIdentifier:@"ID"];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    
}



#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    
  return [[setUpTool alloc] init].array_main.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return [[[setUpTool alloc] init].array_main[section] count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 5;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    setUpTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ID" forIndexPath:indexPath];
    setUpTool *tool = [[setUpTool alloc] init];
    cell.model_cel = tool.array_main[indexPath.section][indexPath.row];
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //    switch (indexPath.section) {
    //        case 0:
    //            NSLog(@"点击1组");
    //            break;
    //        case 1:
    //            switch (indexPath.row) {
    //                case 0:
    //                    NSLog(@"2----0");
    //                    break;
    //
    //                default:
    //                    break;
    //            }
    //            break;
    //        case 2:
    //
    //            break;
    //        default:
    //            NSLog(@"点击最后一组");
    //            break;
    //    }
    switch (indexPath.section) {
        case 0:
            NSLog(@"点击了第一组");
            break;
            
        case 1:
            switch (indexPath.row) {
                case 0:
                {
                    LoginTableViewController *loginVC = [[LoginTableViewController alloc] init];
                    [self.navigationController pushViewController:loginVC animated:YES];
                    
                    NSLog(@"点击了第一组的第一行");
                }
                    break;
                    
                default:
                    break;
            }
            break;
        case 2:
            NSLog(@"点击了第3组");
            break;
        case 3:
            NSLog(@"点击了第4组");
            break;
            
        default:
            break;
    }
    
    
    
    
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    if (section == 3) {
        return 100;
    }
    return 20;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    
    if (section == 3) {
        UIView *view = [[UIView alloc]initWithFrame:CGRectMake(50, 20, 50, 80)];
        
        
        UIButton *but = [[UIButton alloc]initWithFrame:CGRectMake(50, 20, 250, 50)];
        but.backgroundColor = [UIColor redColor];
        [but setTitle:@"退出登录" forState:(UIControlStateNormal)];
        [but addTarget:self action:@selector(resignLogin:) forControlEvents:(UIControlEventTouchUpInside)];
        
        [view addSubview:but];
        return view;
    }
    return nil;
}

- (void)resignLogin:(UIButton *)button{
    
    NSLog(@"退出登录");
    
    FirstLandViewController *loginVC = [[FirstLandViewController alloc]init];
    
   AppDelegate *delegate = [UIApplication sharedApplication].delegate;
    delegate.didLogin = NO;
    [self presentViewController:loginVC animated:YES completion:nil];
    
}


/*
// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}
*/

/*
// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}
*/

/*
// Override to support rearranging the table view.
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
}
*/

/*
// Override to support conditional rearranging of the table view.
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return NO if you do not want the item to be re-orderable.
    return YES;
}
*/

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
